﻿using System;
using System.Windows;
using System.Windows.Controls;
using Omniscient.Foundation.ApplicationModel.Presentation;

namespace Omniscient.TimeTracker.Presentation
{
    public class ExceptionPresenter : IPresenter
    {
        private ExceptionConsole _console;

        public ExceptionPresenter()
        {
            _console = new ExceptionConsole();
            _console.WindowStartupLocation = WindowStartupLocation.Manual;
            _console.Left = 0;
            _console.Top = 0;
            _console.Show();
        }

        public void WriteMessage(object message)
        {
            ExceptionMessage m;
            m = (ExceptionMessage) message;
            TextBlock t = new TextBlock();
            t.TextWrapping = TextWrapping.Wrap;
            t.Text = string.Format("[{0}] Exception occured in {1}.{2}: {3}", 
                                      DateTime.Now, 
                                      m.ClassName, 
                                      m.MethodName, 
                                      m.Message);
            _console.Exceptions.Children.Add(t);        
        }

        public string Name { get { return GetType().Name; } }
        public bool RequiresUserInput { get { return false; } }
    }

    public struct ExceptionMessage
    {
        public string Message { get; set; }
        public string ClassName { get; set; }
        public string MethodName { get; set; }
    }
}